function safe_dofile(fname)
	if CCApplication:sharedApplication():getTargetPlatform() == kTargetAndroid then
		local file_str = c_get_lua_string(fname)	
		local func, msg = loadstring(file_str)
		assert(func)				
		return setfenv(func, _G)()
	else
        local file = CCFileUtils:sharedFileUtils():fullPathForFilename(fname)
		return dofile(file)
	end		
end

safe_dofile("lua/Import.lua")
safe_dofile("lua/cocos2dx/json.lua")
safe_dofile("lua/cocos2dx/extern.lua")
safe_dofile("lua/cocos2dx/CocoStudio.lua")
safe_dofile("lua/cocos2dx/Cocos2d.lua")

--safe_dofile("lua/Functions.lua")
--safe_dofile("lua/Debug.lua")
safe_dofile("lua/Class.lua")
safe_dofile("lua/Object.lua")
--safe_dofile("lua/base.lua")
safe_dofile("lua/DoConfig.lua")
safe_dofile("lua/UI.lua")

MOD_UTIL = loadModule("lua/Functions", false) --工具函数模块名
MOD_ACTION = loadModule("lua/Action",false) --封装的cocos2d-x动作模块名
MOD_CONFIGDB = loadModule("lua/ConfigDB",false) --读取配置数据的模块名
MOD_DEBUG = loadModule("lua/Debug", false) --Debug模块
MOD_PROFILER = loadModule("lua/Profiler",false) --性能分析

--safe_dofile("lua/Action.lua")
local function main()
	--checkUpdate()--检查更新
	local target = CCApplication:sharedApplication():getTargetPlatform()
	if kTargetAndroid ~= target then
		GLOBAL_FONT = 'Helvetica'
	else
		GLOBAL_FONT = 'DroidSans'
	end
	math.randomseed(tonumber(c_get_lua_getOSTime()))
	WRITE_PATH = CCFileUtils:sharedFileUtils():getWritablePath()..'richcat/'
	display = Import("lua/Display.lua").getInstance()
	--启动应用
	local gameMgr = Class("lua/game/clsGameMgr.lua"):getInstance()
	gameMgr:launchApplication()
end	

function __G__TRACKBACK__(msg)
	print("----------------------------------------")
	print("LUA ERROR: " .. tostring(msg) .. "\n")
	print(debug.traceback())
	print("----------------------------------------")
end

xpcall(main, __G__TRACKBACK__)

